
package com.epam.android.training.days45;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.format.Time;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class LinearLayoutDemo extends Activity {

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final Button btn = (Button) findViewById(R.id.button1);
    btn.setOnClickListener(new View.OnClickListener() {

      public void onClick(View v) {
        Intent intent = new Intent(getApplicationContext(), TableLayoutDemo.class);
        startActivityForResult(intent, 0);

      }
    });

  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_menu, menu);
    return true;

  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.current_date:
        Time time = new Time();
        time.setToNow();
        Toast.makeText(getApplicationContext(), time.format("%Y-%m-%dT%H:%M:%S"), Toast.LENGTH_LONG).show();
        break;
      case R.id.change_theme:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.theme_color);
        builder.setItems(getResources().getStringArray(R.array.colors), new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int item) {
            switch (item) {
              case 0:
                changeStyle(R.style.CodeFont_Red);
                break;
              case 1:
                changeStyle(R.style.CodeFont);
                break;
              case 2:
                changeStyle(R.style.CodeFont_Blue);
                break;
            }

          }
        });
        builder.show();
        break;
    }
    return true;
  }

  private void changeStyle(int style) {
    ((TextView) findViewById(R.id.main_text_view)).setTextAppearance(getApplicationContext(), style);
  }
}
